package com.liaoxuefeng.ref_exe;

public class ReflectionTest {

    public static void main(String[] args) throws ClassNotFoundException {
        Class<String> cls = String.class;
        String s = "Hello";
        Class cls2 = s.getClass();
        Class cls3 = Class.forName("java.lang.String");
        System.out.println(cls == cls2); // true

        printClassInfo("".getClass());
        printClassInfo(Runnable.class);
        printClassInfo(java.time.Month.class);
        printClassInfo(String[].class);
        printClassInfo(int.class);
    }

    static void printClassInfo(Class cls) {
        System.out.println("Class name: " + cls.getName());
        System.out.println("Simple name: " + cls.getSimpleName());
        if (cls.getPackage() != null) {
            System.out.println("package name: " + cls.getPackage().getName());
        }
        System.out.println("is interface: " + cls.isInterface());
        System.out.println("is enum: " + cls.isEnum());
        System.out.println("is array: " + cls.isArray());
        System.out.println("is primitive: " + cls.isPrimitive());
    }
}
